package com.ruoyi.web.controller.wbgame;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wbgame.domain.WbItemType;
import com.ruoyi.wbgame.service.IWbItemTypeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 题型Controller
 * 
 * @author guguofu
 * @date 2021-04-19
 */
@Controller
@RequestMapping("/wbgame/itemType")
public class WbItemTypeController extends BaseController
{
    private String prefix = "wbgame/itemType";

    @Autowired
    private IWbItemTypeService wbItemTypeService;

    @RequiresPermissions("wbgame:itemType:view")
    @GetMapping()
    public String itemType()
    {
        return prefix + "/itemType";
    }

    /**
     * 查询题型列表
     */
    @RequiresPermissions("wbgame:itemType:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WbItemType wbItemType)
    {
        startPage();
        List<WbItemType> list = wbItemTypeService.selectWbItemTypeList(wbItemType);
        return getDataTable(list);
    }

    /**
     * 导出题型列表
     */
    @RequiresPermissions("wbgame:itemType:export")
    @Log(title = "题型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WbItemType wbItemType)
    {
        List<WbItemType> list = wbItemTypeService.selectWbItemTypeList(wbItemType);
        ExcelUtil<WbItemType> util = new ExcelUtil<WbItemType>(WbItemType.class);
        return util.exportExcel(list, "itemType");
    }

    /**
     * 新增题型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存题型
     */
    @RequiresPermissions("wbgame:itemType:add")
    @Log(title = "题型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WbItemType wbItemType)
    {
        return toAjax(wbItemTypeService.insertWbItemType(wbItemType));
    }

    /**
     * 修改题型
     */
    @GetMapping("/edit/{itemTypeId}")
    public String edit(@PathVariable("itemTypeId") Long itemTypeId, ModelMap mmap)
    {
        WbItemType wbItemType = wbItemTypeService.selectWbItemTypeById(itemTypeId);
        mmap.put("wbItemType", wbItemType);
        return prefix + "/edit";
    }

    /**
     * 修改保存题型
     */
    @RequiresPermissions("wbgame:itemType:edit")
    @Log(title = "题型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WbItemType wbItemType)
    {
        return toAjax(wbItemTypeService.updateWbItemType(wbItemType));
    }

    /**
     * 删除题型
     */
    @RequiresPermissions("wbgame:itemType:remove")
    @Log(title = "题型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wbItemTypeService.deleteWbItemTypeByIds(ids));
    }
}
